package com.nmf.site.common.service;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.nmf.site.common.enums.OfficeTypeEnums;
import com.nmf.site.modules.sys.entity.Role;
import com.nmf.site.modules.sys.entity.User;
import com.nmf.site.modules.sys.utils.UserUtils;

public class SysNameService {
	public static String yttEnname = "ytt";
	public static void setSysName(HttpServletRequest request) {
		String js2 = (String)request.getAttribute("js");
		if(js2==null) {
			js2 =  (String)request.getParameter("js");
		}
		User user = UserUtils.getUser();
		if(user!=null && js2==null && user.getRoleList().size()>0) {
			String enName = user.getRoleList().get(0).getEnname();
			if(yttEnname.equalsIgnoreCase(enName)) {
				OfficeTypeEnums officeTypeEnums = OfficeTypeEnums.getType(user.getOffice().getType());
				if(OfficeTypeEnums.COMP.equals(officeTypeEnums)) {
					request.setAttribute("pname", "国家工程研究中心信息填报系统");
				}else if(OfficeTypeEnums.GONGCHENG.equals(officeTypeEnums)) {
					request.setAttribute("pname", "国家工程中⼼信息填报系统");
				}else if(OfficeTypeEnums.YANJIU.equals(officeTypeEnums)) {
					request.setAttribute("pname", "国家研究中⼼信息填报系统");
				}
			}else if("nrfb".equalsIgnoreCase(enName)) {
				request.setAttribute("pname", "国家创新驱动发展数据平台内容发布系统");
			}else if("yyzy".equalsIgnoreCase(enName)) {
				request.setAttribute("pname", "国家工程中心（企业技术中心）认定与运行评价系统");
			}else if("sys".equalsIgnoreCase(enName)) {
				request.setAttribute("pname", "权限管理系统");
			}else if("gjyunying".equalsIgnoreCase(enName)) {
				request.setAttribute("pname", "国家运营中心");
			}
		}else {
			if(js2==null || "ytdw".equalsIgnoreCase(js2)) {
				request.setAttribute("pname", "国家工程研究中心信息填报系统");
				request.setAttribute("yemei", "国家/地方审查管理部门");
			}else if("nr".equalsIgnoreCase(js2)) {
				request.setAttribute("pname", "国家创新驱动发展数据平台内容发布系统");
			}else if("yy".equalsIgnoreCase(js2)) {
				request.setAttribute("pname", "国家工程中心（企业技术中心）认定与运行评价系统");
			}else if("sys".equalsIgnoreCase(js2)) {
				request.setAttribute("pname", "权限管理系统");
			}else if("guojia".equalsIgnoreCase(js2)) {
				request.setAttribute("pname",  "国家运营中心");
			}
			request.setAttribute("js", js2);
		}
	}
	
	public static String getRightName() {
		List<Role> roleList = UserUtils.getRoleList();
		if("nrfb".equalsIgnoreCase(roleList.get(0).getEnname())||"gjyunying".equalsIgnoreCase(roleList.get(0).getEnname())||yttEnname.equalsIgnoreCase(roleList.get(0).getEnname())) {
			return UserUtils.getUser().getOffice().getName();
		}else{
			return roleList.get(0).getName();
		}
	}
}
